<template>
  <div class="app-container home">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['client:messages:submitClientForm']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:role:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:role:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:role:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-form :model="sysClient" ref="sysClient" size="small" :inline="true" label-width="68px">
      <el-form-item label="用户名称" prop="name">
        <el-input
          v-model="sysClient.name"
          placeholder="请输入用户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="clientLists">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
<!--    <h1>念小孩</h1>-->
    <el-table v-loading="loading" :data="clientData" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="客户名称" prop="name" width="150" />
      <el-table-column label="地址" prop="addr" :show-overflow-tooltip="true" width="300" />
      <el-table-column label="邮箱" prop="email" :show-overflow-tooltip="true" width="180" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" >
        <template slot-scope="scope" v-if="scope.row.roleId !== 1">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="getlinkmanById(scope.row.id)"
            v-hasPermi="['client:messages:getlinkmanById']"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:role:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:role:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
<!--分页-->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="sysClient.pageNum"
      :limit.sync="sysClient.pageSize"
      @pagination="clientLists"
    />

<!--   打开 客户添加表单-->
    <el-dialog :title="title" :visible.sync="openClientForm" width="500px" append-to-body>
      <el-form ref="form" :model="clientForm" :rules="rules" label-width="100px">
        <el-form-item label="客户名称" prop="roleName">
          <el-input v-model="clientForm.name" placeholder="请输入角色名称" />
        </el-form-item>
        <el-form-item label="地址" prop="roleSort">
          <el-input v-model="clientForm.addr" placeholder="请输入地址" />
        </el-form-item>
        <el-form-item label="邮箱">
<!--          <el-input v-model="clientForm.remark" type="textarea" placeholder="请输入内容"></el-input>-->
          <el-input v-model="clientForm.email" placeholder="请输入邮箱" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitClientForm">确 定</el-button>
        <el-button @click="openView">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {clientList, getLinkmanList,submitClientForm} from "@/api/client/messages";

export default {
  name: "index",
  data() {
    return {
      openClientForm:false,
      // 版本号
      version: "3.8.7",
      loading:true,
      clientData:[],
      sysClient:{
        pageNum:1,
        pageSize:10,
        name:''
      },
      total:0,
      // 显示搜索条件
      showSearch: true,
      clientForm:{}
    };
  },
  methods: {
    clientLists(){
      this.loading=true
      clientList(this.sysClient).then(response => {
        this.clientData=response.rows;
        this.total = response.total;
        this.loading=false
      })
    },/** 搜索按钮操作 */
    handleQuery() {
      this.sysClient.pageNum = 1;
      this.clientLists();
    },/** 重置按钮操作 */
    resetQuery() {
      this.resetForm("sysClient");
      this.handleQuery();
    },/*通过id去查看联系人列表*/
    getlinkmanById(clientId){
      //alert(id)
      this.$router.push({path:'/client/linkman',query:{clientId:clientId}})
    },/*关闭查看联系人列表*/
    openView(){
      this.openLinkmanView=false;
      this.openClientForm=false
    },/*打开新增客户表单*/
    handleAdd(){
      this.openClientForm=true
    },/*提交客户表单*/
    submitClientForm(){
      submitClientForm(this.clientForm).then(res=>{

      })
    }
  },created() {
    this.clientLists()
  }
}
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }
  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }
  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
</style>

